package com.ruoyi.operators.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.operators.domain.Operators;
import com.ruoyi.operators.service.IOperatorsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 算子Controller
 * 
 * @author ruoyi
 * @date 2023-05-26
 */
@RestController
@RequestMapping("/ruoyi-operators/operators")
public class OperatorsController extends BaseController
{
    @Autowired
    private IOperatorsService operatorsService;

    /**
     * 查询算子列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-operators:operators:list')")
    @GetMapping("/list")
    public TableDataInfo list(Operators operators)
    {
        startPage();
        List<Operators> list = operatorsService.selectOperatorsList(operators);
        return getDataTable(list);
    }

    /**
     * 导出算子列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-operators:operators:export')")
    @Log(title = "算子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Operators operators)
    {
        List<Operators> list = operatorsService.selectOperatorsList(operators);
        ExcelUtil<Operators> util = new ExcelUtil<Operators>(Operators.class);
        util.exportExcel(response, list, "算子数据");
    }

    /**
     * 获取算子详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-operators:operators:query')")
    @GetMapping(value = "/{name}")
    public AjaxResult getInfo(@PathVariable("name") String name)
    {
        return success(operatorsService.selectOperatorsByName(name));
    }

    /**
     * 新增算子
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-operators:operators:add')")
    @Log(title = "算子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Operators operators)
    {
        return toAjax(operatorsService.insertOperators(operators));
    }

    /**
     * 修改算子
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-operators:operators:edit')")
    @Log(title = "算子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Operators operators)
    {
        return toAjax(operatorsService.updateOperators(operators));
    }

    /**
     * 删除算子
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-operators:operators:remove')")
    @Log(title = "算子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{names}")
    public AjaxResult remove(@PathVariable String[] names)
    {
        return toAjax(operatorsService.deleteOperatorsByNames(names));
    }
}
